﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.Reporting.WebForms;
using BOHVote.BLL;
using BOHVote.Common;

namespace BOH.Information.Report
{
    public partial class PersonalInfoReport : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.Title = common.getAppSetting("AppName");
                string  SubjectName = string.Empty;
                string  GovernName = string.Empty;
                string ApplyImg = string.Empty;
                string Period = string.Empty;
                if(Request.QueryString["ID"]!=null&&!string.IsNullOrEmpty(Request.QueryString["ID"].ToString()))
                {
                    string ApplyID = Request.QueryString["ID"].ToString();

                    XSD.PersonalInfo xsd = BindReport(ApplyID, out SubjectName, out GovernName, out ApplyImg,out Period);

                    ReportViewBind(xsd);//, SubjectName, GovernName, ApplyImg, "", Period);
                }
                else if(Request.QueryString["ApplyStyle"]!=null&&Request.QueryString["ApplyType"]!=null&&Request.QueryString["Govern"]!=null&&Request.QueryString["Unit"]!=null&&Request.QueryString["Subject"]!=null&&Request.QueryString["Speciality"]!=null&&Request.QueryString["ApplyJobRank"]!=null)
                {
                    string ApplyStyle = Request.QueryString["ApplyStyle"].ToString();
                    string ApplyType = Request.QueryString["ApplyType"].ToString();
                    string Govern = Request.QueryString["Govern"].ToString();
                    string Unit = Request.QueryString["Unit"].ToString();
                    string Subject = Request.QueryString["Subject"].ToString();
                    string Speciality = Request.QueryString["Speciality"].ToString();
                    string ApplyJobRank = Request.QueryString["ApplyJobRank"].ToString();
                    //DataSet dst = ApplyClass.dstApplys(Unit, Govern, ApplyStyle, ApplyType, Speciality, Subject, ApplyJobRank, (string)Session["ApplyPeriod"]);
                    XSD.PersonalInfo xsd = BindPersonalList(Unit, Govern, ApplyStyle, ApplyType, Speciality, Subject, ApplyJobRank, (string)Session["ApplyPeriod"]);
                    ReportViewBind(xsd);
                }
            }
        }

        public XSD.PersonalInfo BindPersonalList(string Unit, string Govern, string ApplyStyle, string ApplyType, string Speciality, string Subject, string ApplyJobRank, string ApplyPeriod)
        { 
             XSD.PersonalInfo personalXSD = new BOH.XSD.PersonalInfo();
             //DataSet dst = ApplyClass.dstAllInfoApplys(Unit, Govern, ApplyStyle, ApplyType, Speciality, Subject, ApplyJobRank, (string)Session["ApplyPeriod"]);
             string ApplyImage = string.Empty;
             string strPeriod = string.Empty;
        //    foreach (DataRow dr in dst.Tables[0].Rows)
        //    {
        //        DataRow drNew = personalXSD.Tables["PersonalInfo"].NewRow();
        //        drNew["ApplyID"] = dr["ApplyID"].ToString();
        //        drNew["ApplyName"] = dr["Apply_Name"].ToString();
        //        drNew["ApplyMobile"] = dr["ApplyMobile"].ToString();
        //        drNew["UnitGovernName"] = dr["UnitGovernName"].ToString();
        //        drNew["GovernName"] = dr["GovernName"].ToString();
        //        drNew["ApplyPeriod"] = dr["ApplyPeriodID"].ToString();
        //        drNew["Gender"] = dr["Gender"].ToString();

        //        if (!string.IsNullOrEmpty(dr["Birthday"].ToString()))
        //            drNew["Birthday"] = Convert.ToDateTime(dr["Birthday"].ToString()).ToString("yyyy-MM");
        //        else
        //            drNew["Birthday"] = "-";

        //        drNew["EducationLevel"] = dr["EducationLevel"].ToString();
        //        drNew["IDCard"] = dr["IDCard"].ToString();
        //        drNew["School"] = dr["School"].ToString();
        //        if (!string.IsNullOrEmpty(dr["GraduationDate"].ToString()))
        //            drNew["GraduationDate"] = Convert.ToDateTime(dr["GraduationDate"].ToString()).ToString("yyyy-MM");
        //        else
        //            drNew["GraduationDate"] = "-";

        //        drNew["CurrentJobRank"] = dr["CurrentJobRankID"].ToString();
        //        drNew["ApplyType"] = dr["ApplyType"].ToString();
        //        drNew["SpecialityID"] = dr["SpecialityID"].ToString();
        //        drNew["JobRankID"] = dr["JobRankID"].ToString();
        //        drNew["SubjectID"] = dr["SubjectID"].ToString();

        //        if (!string.IsNullOrEmpty(dr["JobDate"].ToString()))
        //            drNew["JobDate"] = Convert.ToDateTime(dr["JobDate"].ToString()).ToString("yyyy-MM");
        //        else
        //            drNew["JobDate"] = "-";

        //        if (!string.IsNullOrEmpty(dr["ConversionDate"].ToString()))
        //            drNew["ConversionDate"] = Convert.ToDateTime(dr["ConversionDate"].ToString()).ToString("yyyy-MM");
        //        else
        //            drNew["ConversionDate"] = "-";

        //        drNew["JobTerm"] = dr["JobTerm"].ToString();
        //        drNew["FixedJob"] = dr["FixedJob"].ToString();
        //        drNew["ForeignLanguageName"] = dr["ForeignLanguageName"].ToString();
        //        drNew["ForeignLanguageResult"] = dr["ForeignLanguageResult"].ToString();
        //        drNew["PoliticsResult"] = dr["PoliticsResult"].ToString();
        //        drNew["JobResult"] = dr["JobResult"].ToString();
        //        drNew["ComputerResult"] = dr["ComputerResult"].ToString();
        //        drNew["Applyplight"] = dr["Applyplight"].ToString();

        //        if (!string.IsNullOrEmpty(dr["LastApplyDate"].ToString()))
        //            drNew["LastApplyDate"] = Convert.ToDateTime(dr["LastApplyDate"].ToString()).ToString("yyyy-MM");
        //        else
        //            drNew["LastApplyDate"] = "-";

        //        drNew["SpecialityName"] = dr["SpecialityName"].ToString();
        //        drNew["SpecialityLevel"] = dr["SpecialityLevel"].ToString();
        //        drNew["SpecialitapproveUnit"] = dr["SpecialitapproveUnit"].ToString();
        //        drNew["SpecialitPersonalRank"] = dr["SpecialitPersonalRank"].ToString();

        //        if (!string.IsNullOrEmpty(dr["SpecialitDateTime"].ToString()))
        //            drNew["SpecialitDateTime"] = Convert.ToDateTime(dr["SpecialitDateTime"].ToString()).ToString("yyyy-MM");
        //        else
        //            drNew["SpecialitDateTime"] = "-";

        //        drNew["AwardsName"] = dr["AwardsName"].ToString();
        //        drNew["AwardsLevel"] = dr["AwardsLevel"].ToString();
        //        drNew["AwardsRank"] = dr["AwardsRank"].ToString();
        //        drNew["AwardsPersonalRank"] = dr["AwardsPersonalRank"].ToString();

        //        if (!string.IsNullOrEmpty(dr["AwardsDateTime"].ToString()))
        //            drNew["AwardsDateTime"] = Convert.ToDateTime(dr["AwardsDateTime"].ToString()).ToString("yyyy-MM");
        //        else
        //            drNew["AwardsDateTime"] = "-";

        //        drNew["JournalsNo1"] = dr["JournalsNo1"].ToString();
        //        drNew["ThesisTitle1"] = dr["ThesisTitle1"].ToString();
        //        drNew["JournalsNo2"] = dr["JournalsNo2"].ToString();
        //        drNew["ThesisTitle2"] = dr["ThesisTitle2"].ToString();
        //        drNew["JournalsNo3"] = dr["JournalsNo3"].ToString();
        //        drNew["ThesisTitle3"] = dr["ThesisTitle3"].ToString();
        //        drNew["JournalsNo4"] = dr["JournalsNo4"].ToString();
        //        drNew["ThesisTitle4"] = dr["ThesisTitle4"].ToString();
        //        drNew["ApplyPrintID"] = dr["ApplyPrintID"].ToString();
        //        drNew["ApplyStyle"] = dr["ApplyStyle"].ToString();

        //        drNew["startmonth"] = dr["startmonth"].ToString();
        //        drNew["startday"] = dr["startday"].ToString();
        //        drNew["endmonth"] = dr["endmonth"].ToString();
        //        drNew["endday"] = dr["endday"].ToString();
        //        drNew["address"] = dr["address"].ToString();
        //        drNew["response"] = dr["response"].ToString();

        //        strPeriod = dr["ApplyPeriodID"].ToString();
        //        if (!string.IsNullOrEmpty(dr["ApplyImage"].ToString()))
        //            ApplyImage = common.getAppSetting("FolderforLoadPath") + "/" + strPeriod + "/" + dr["ApplyImage"].ToString();//Server.MapPath("UploadFile") + "\\" + ApplyImg;
        //        else
        //            ApplyImage = common.getAppSetting("FolderforLoadPath") + "/blank.JPG";
        //        drNew["ApplyImage"] = ApplyImage;  
        //        personalXSD.Tables["PersonalInfo"].Rows.Add(drNew);
        //    }
             return personalXSD;
        }

        public XSD.PersonalInfo BindReport(string ApplyID, out string SubjectName, out string GovernName, out string ApplyImg,out string Period)
        {
            string strSubjectName = string.Empty;
            string strGovernName = string.Empty;
            string strApplyImg = string.Empty;
            string strPeriod = string.Empty;
            string ApplyImage = string.Empty;
            XSD.PersonalInfo personalXSD = new BOH.XSD.PersonalInfo();
            DataSet dst  = ApplyClass.getApplyInfoByApplyID(ApplyID);
            foreach (DataRow dr in dst.Tables[0].Rows)
            {
                DataRow drNew = personalXSD.Tables["PersonalInfo"].NewRow();
                drNew["ApplyID"] = dr["ApplyID"].ToString();
                drNew["ApplyName"] = dr["Apply_Name"].ToString();
                drNew["ApplyMobile"] = dr["ApplyMobile"].ToString();
                drNew["UnitGovernName"] = dr["UnitGovernName"].ToString();
                drNew["GovernName"] = dr["GovernName"].ToString();
                drNew["ApplyPeriod"] = dr["ApplyPeriodID"].ToString();
                drNew["Gender"] = dr["Gender"].ToString();

                if (!string.IsNullOrEmpty(dr["Birthday"].ToString()))
                    drNew["Birthday"] = Convert.ToDateTime(dr["Birthday"].ToString()).ToString("yyyy-MM");
                else
                    drNew["Birthday"] = "-";
                
                drNew["EducationLevel"] = dr["EducationLevel"].ToString();
                drNew["IDCard"] = dr["IDCard"].ToString();
                drNew["School"] = dr["School"].ToString();

                if (!string.IsNullOrEmpty(dr["GraduationDate"].ToString()))
                    drNew["GraduationDate"] = Convert.ToDateTime(dr["GraduationDate"].ToString()).ToString("yyyy-MM");
                else
                    drNew["GraduationDate"] = "-";

                drNew["CurrentJobRank"] = dr["CurrentJobRankID"].ToString();
                drNew["ApplyType"] = dr["ApplyType"].ToString();
                drNew["SpecialityID"] = dr["SpecialityID"].ToString();
                drNew["JobRankID"] = dr["JobRankID"].ToString();
                drNew["SubjectID"] = dr["SubjectID"].ToString();

                if (!string.IsNullOrEmpty(dr["JobDate"].ToString()))
                    drNew["JobDate"] = Convert.ToDateTime(dr["JobDate"].ToString()).ToString("yyyy-MM");
                else
                    drNew["JobDate"] = "-";


                if (!string.IsNullOrEmpty(dr["ConversionDate"].ToString()))
                    drNew["ConversionDate"] = Convert.ToDateTime(dr["ConversionDate"].ToString()).ToString("yyyy-MM");
                else
                    drNew["ConversionDate"] = "-";

                drNew["JobTerm"] = dr["JobTerm"].ToString();
                drNew["FixedJob"] = dr["FixedJob"].ToString();
                drNew["ForeignLanguageName"] = dr["ForeignLanguageName"].ToString();
                drNew["ForeignLanguageResult"] = dr["ForeignLanguageResult"].ToString();
                drNew["PoliticsResult"] = dr["PoliticsResult"].ToString();
                drNew["JobResult"] = dr["JobResult"].ToString();
                drNew["ComputerResult"] = dr["ComputerResult"].ToString();
                drNew["Applyplight"] = dr["Applyplight"].ToString();

                if (!string.IsNullOrEmpty(dr["LastApplyDate"].ToString()))
                    drNew["LastApplyDate"] = Convert.ToDateTime(dr["LastApplyDate"].ToString()).ToString("yyyy-MM");
                else
                    drNew["LastApplyDate"] = "-";

                drNew["SpecialityName"] = dr["SpecialityName"].ToString();
                drNew["SpecialityLevel"] = dr["SpecialityLevel"].ToString();
                drNew["SpecialitapproveUnit"] = dr["SpecialitapproveUnit"].ToString();
                drNew["SpecialitPersonalRank"] = dr["SpecialitPersonalRank"].ToString();

                if (!string.IsNullOrEmpty(dr["SpecialitDateTime"].ToString()))
                    drNew["SpecialitDateTime"] = Convert.ToDateTime(dr["SpecialitDateTime"].ToString()).ToString("yyyy-MM");
                else
                    drNew["SpecialitDateTime"] = "-";

                drNew["AwardsName"] = dr["AwardsName"].ToString();
                drNew["AwardsLevel"] = dr["AwardsLevel"].ToString();
                drNew["AwardsRank"] = dr["AwardsRank"].ToString();
                drNew["AwardsPersonalRank"] = dr["AwardsPersonalRank"].ToString();

                if (!string.IsNullOrEmpty(dr["AwardsDateTime"].ToString()))
                    drNew["AwardsDateTime"] = Convert.ToDateTime(dr["AwardsDateTime"].ToString()).ToString("yyyy-MM");
                else
                    drNew["AwardsDateTime"] = "-";

                drNew["JournalsNo1"] = dr["JournalsNo1"].ToString();
                drNew["ThesisTitle1"] = dr["ThesisTitle1"].ToString();
                drNew["JournalsNo2"] = dr["JournalsNo2"].ToString();
                drNew["ThesisTitle2"] = dr["ThesisTitle2"].ToString();
                drNew["JournalsNo3"] = dr["JournalsNo3"].ToString();
                drNew["ThesisTitle3"] = dr["ThesisTitle3"].ToString();
                drNew["JournalsNo4"] = dr["JournalsNo4"].ToString();
                drNew["ThesisTitle4"] = dr["ThesisTitle4"].ToString();
                drNew["ApplyPrintID"] = dr["ApplyPrintID"].ToString();
                drNew["ApplyStyle"] = dr["ApplyStyle"].ToString();

                drNew["startmonth"] = dr["startmonth"].ToString();
                drNew["startday"] = dr["startday"].ToString();
                drNew["endmonth"] = dr["endmonth"].ToString();
                drNew["endday"] = dr["endday"].ToString();
                drNew["address"] = dr["address"].ToString();
                drNew["response"] = dr["response"].ToString();
                
                strPeriod = dr["ApplyPeriodID"].ToString();
                if (!string.IsNullOrEmpty(dr["ApplyImage"].ToString()))
                    ApplyImage = common.getAppSetting("FolderforLoadPath") + "/" + strPeriod + "/" + dr["ApplyImage"].ToString();//Server.MapPath("UploadFile") + "\\" + ApplyImg;
                else
                    ApplyImage = common.getAppSetting("FolderforLoadPath") + "/blank.JPG";
                drNew["ApplyImage"] = ApplyImage;  
                personalXSD.Tables["PersonalInfo"].Rows.Add(drNew);

                strSubjectName = dr["SubjectID"].ToString();
                strGovernName = dr["GovernID"].ToString();
                strApplyImg = dr["ApplyImage"].ToString();
                
            }

            SubjectName = strSubjectName;
            GovernName = strGovernName;
            ApplyImg = strApplyImg;
            Period = strPeriod;
            return personalXSD;
        }

        public void ReportViewBind(XSD.PersonalInfo personalXSD)//, string SubjectName, string GovernName, string ApplyImg, string SerialNo, string strPeriod)
        {
            ReportDataSource datasource = new ReportDataSource("PersonalInfo_PersonalInfo", personalXSD.Tables["PersonalInfo"]);
            ReportViewer1.LocalReport.DataSources.Clear();
            ReportViewer1.LocalReport.DataSources.Add(datasource);
            ReportViewer1.LocalReport.EnableExternalImages = true;
            //ReportParameter[] param = new ReportParameter[4];
            //if (!string.IsNullOrEmpty(ApplyImg))
            //    ApplyImg = common.getAppSetting("FolderforLoadPath") + "/" + strPeriod +"/"+ ApplyImg;//Server.MapPath("UploadFile") + "\\" + ApplyImg;
            //else
            //    ApplyImg = common.getAppSetting("FolderforLoadPath") + "/blank.JPG";
            //string path = ApplyImg;
            //param[0] = new ReportParameter("img", path);
            //param[1] = new ReportParameter("GovernName", GovernName);
            //param[2] = new ReportParameter("SubjectName", SubjectName);
            //param[3] = new ReportParameter("SerialNo", SerialNo);
            //ReportViewer1.LocalReport.SetParameters(param);
            ReportViewer1.LocalReport.Refresh();
        }

    }
}
